//
//  LevelTestViewController.m
//  MIDI
//
//  Created by E.M.Game on 15/9/10.
//  Copyright (c) 2015年 QXSX. All rights reserved.
//

#import "LevelTestViewController.h"
#import "AppConfig.h"
#import "LevelTestCell.h"
#import "ExamSignPrimeViewController.h"
#import "ExamProcessViewController.h"
#import "ClassVideoDetailViewController.h"
#import "PrepareGuideViewController.h"
#import "QueryViewController.h"
#import "MrMIDISearchViewCtrler.h"
#import "UserDataSingleton.h"
#import "QXNetWorkTool.h"
#import "MBProgressHUD+YC.h"
#import "APIAdress.h"
#import "AboutMIDIModel.h"
#import "AboutMIDISubWebViewController.h"

@interface LevelTestViewController() <UITabBarControllerDelegate , UITableViewDataSource,UITableViewDelegate
    ,LevelTestCellDeletage, QXNetWorkToolDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) AboutMIDIModel *model;

@end

@implementation LevelTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self configNavigationItem];
    
    [self config];
}


-(void) config
{
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool *tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName:AboutMIDIInterface 	andParameter:@[@{@"article_id":@"grading_process"}] tag:1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void) configNavigationItem
{
    [self.navigationController.navigationBar setTranslucent:NO];
    [self.tabBarController configNavigationBarTintColor:UIColorRGBA(0, 0, 0, 1)];
    [self.navigationController.navigationBar setBarTintColor:MIDIColorOfNavigationBar];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    //self.navigationItem.title = @"考级";
    self.tabBarController.navigationItem.title = @"考级";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],UITextAttributeFont,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
}

#pragma mark tableView datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return 99;
    }
    return 86;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LevelTestCell  *cell = nil;
    NSString *id = @"LevelTestCell";
    cell = [self.tableView dequeueReusableCellWithIdentifier:id];
    if(cell ==nil)
    {
        cell = [LevelTestCell loadFromNib];
        cell.levelTestCellDelegate = self;
    }
    [self configCell : indexPath.row cell:cell];
    return cell;
}

#pragma mark - Table View Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


-(void)pressLeft:(UIButton *)sender
{
    
    [self.navigationController popViewControllerAnimated:YES];
    NSLog(@"press left");
}


-(void)configCell : (NSInteger)row cell :(LevelTestCell*) myCell
{
    switch (row) {
        case 0:
            myCell.titleImg.image = [UIImage imageNamed:@"ico_levelTest_signUp"];
            [myCell.titleLabel setText:@"报名考试"];
            break;
        case 1:
            myCell.titleImg.image =[UIImage imageNamed:@"ico_levelTest_processChart"];
            [myCell.titleLabel setText:@"考级流程"];
            break;
        case 2:
            myCell.titleImg.image = [UIImage imageNamed:@"ico_levelTest_openClassVideo"];
            [myCell.titleLabel setText:@"公开课视频"];
            break;
        case 3:
            myCell.titleImg.image = [UIImage imageNamed:@"ico_levelTest_examGuide"];
            [myCell.titleLabel setText:@"备考指南"];
            break;
        case 4:
            myCell.titleImg.image = [UIImage imageNamed:@"ico_levelTest_certificate"];
            [myCell.titleLabel setText:@"考级证书"];
            break;
        case 5:
            myCell.titleImg.image = [UIImage imageNamed:@"ico_levelTest_mrMidi"];
            [myCell.titleLabel setText:@"迷笛先生"];
            break;
        default:
            break;
    }
}

-(void)clickTitleIndex:(int) titleIndex
{
    switch (titleIndex) {
        case 0:
        {
            [self.navigationController pushViewController:
                  [ExamSignPrimeViewController create] animated:YES];
        }
            break;
        case 1:
        {
            
            ExamProcessViewController *obj = [ExamProcessViewController create];
            
            obj.url = self.model.url;
            
            [self.navigationController pushViewController:obj animated:YES];
        }
            break;
        case 2:
        {
            [self.navigationController pushViewController:
             [ClassVideoDetailViewController create] animated:YES];
        }
            break;
        case 3:
        {
            [self.navigationController pushViewController:
             [PrepareGuideViewController create] animated:YES];
        }
            break;
        case 4:
        {
            [self.navigationController pushViewController:
             [QueryViewController create] animated:YES];
        }
            break;
        case 5:
        {
            MrMIDISearchViewCtrler *obj = [MrMIDISearchViewCtrler create];
            obj.isShowMrMIDISearchBgAndScreening = YES;
            obj.curcity = [UserDataSingleton shareInstance].curCityId;
            obj.curcityName = [UserDataSingleton shareInstance].cityName;
            
            [self.navigationController pushViewController:obj animated:YES];
        }
            break;
        default:
            break;
    }
}


-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (tag == 1)
    {
        for (NSDictionary *dic in Response)
        {
            self.model = [AboutMIDIModel AboutMIDIModelWithDict:dic];
            
            break;
        }
        
        return;
    }
}

-(void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
}

@end


























